package iBuyCoolSky.service.call;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;
import java.util.Vector;

import iBuyCoolSky.service.call.model.IBuyCoolSkyModel;

import org.codehaus.xfire.XFireFactory;
import org.codehaus.xfire.client.Client;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;

import iBuyCoolSky.service.call.CustomServiceFactory;

import iBuyCoolSky.service.call.model.Good;
import iBuyCoolSky.service.call.model.OrderEntryData;

import com.sun.org.apache.xerces.internal.util.URI;

import dataClass.Product;



import iBuyCoolSky.service.call.model.IBuyCoolSkyModel;

public class CoolSkyService implements IBuyCoolSkyModel{

	/**
	 * @param args
	 */
	private static Service srvcModel = new CustomServiceFactory().create(IBuyCoolSkyModel.class);
	private static XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());
	private static String servURL = "http://166.111.68.169:5041/service1.asmx";
	private static IBuyCoolSkyModel svc = null;
	public static Client client;

	
	static {
		init();
	}
	
	public static void init() {
		if (svc == null) {
			try {
				svc = (IBuyCoolSkyModel)factory.create(srvcModel, servURL);
			}catch (Exception e) {
				
			}
		}
	}

	public Double GetDiscount(String agencyName, String type) {
		// TODO Auto-generated method stub
		return svc.GetDiscount(agencyName,type);
	}
	public Good[] GetGoods() {
		// TODO Auto-generated method stub
		return svc.GetGoods();
	}
	public String[] GetProducers() {
		// TODO Auto-generated method stub
		return svc.GetProducers();
	}
	public String[] GetTypes() {
		// TODO Auto-generated method stub
		return svc.GetTypes();
	}
	public boolean ProcessOrder(String agencyName,
			OrderEntryData[] orderEntryDatas) {
		// TODO Auto-generated method stub
		return svc.ProcessOrder(agencyName, orderEntryDatas);
	}
	public Good[] QueryGoodByDeliveryTime(Date lowerBound, Date upperBound) {
		// TODO Auto-generated method stub
		return svc.QueryGoodByDeliveryTime(lowerBound, upperBound);
	}
	public Good[] QueryGoodByPrice(double lowerBound, double upperBound) {
		// TODO Auto-generated method stub
		return svc.QueryGoodByPrice(lowerBound, upperBound);
	}
	public Good[] QueryGoodByProducer(String[] producers) {
		// TODO Auto-generated method stub
		return svc.QueryGoodByProducer(producers);
	}
	public Good[] QueryGoodByStoreAmount(long lowerBound, long upperBound) {
		// TODO Auto-generated method stub
		return svc.QueryGoodByStoreAmount(lowerBound, upperBound);
	}
	public Good QueryGoodsById(int id) {
		// TODO Auto-generated method stub
		return svc.QueryGoodsById(id);
	}
	public Good[] QueryGoodsByName(String[] names) {
		// TODO Auto-generated method stub
		return svc.QueryGoodsByName(names);
	}
	public Good[] QueryGoodsByType(String[] types) {
		// TODO Auto-generated method stub
		return svc.QueryGoodsByType(types);
	}
	

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		CoolSkyService ns = new CoolSkyService();
		
		String[] types = ns.GetTypes();
		System.out.println(ns.GetDiscount("coo", ""));
		System.out.println("QueryGoodsById:" + ns.QueryGoodsById(1000).toString());
		for (String type : types) {
			System.out.println(type);
		}
		Good[] goods = ns.GetGoods();
		String[] str = {"CPU"};
		Good[] good2 = ns.QueryGoodsByType(types);
		for (Good good : goods) {
			System.out.println(good.toString());
		}
		for (Good good : good2) {
			System.out.println(good.toString());
		}
	}
}
